<template>
  <div class="comments">
    <ItemTitle
      itemName="精彩评论"
      style="color: #fff; border: none; margin-bottom: 0"
    >
    </ItemTitle>
    <ul>
      <li v-for="(item, index) in commentList" :key="index">
        <!-- -->
        <div class="imgbox">
          <img :src="item.user.avatarUrl" />
        </div>
        <div class="cmtbox">
          <div class="head">
            <div class="textbox">
              <p>{{ item.user.nickname }}</p>
              <span>{{ item.time | formatdate(item) }}</span>
            </div>
            <div class="count">
              <p>{{ item.likedCount }}</p>
              <i>
                <svg
                  class="u-svg u-svg-unzancmt"
                  xmlns="http://www.w3.org/2000/svg"
                  viewBox="0 0 28 28"
                >
                  <path
                    fill="#999"
                    d="m25.857 14.752c-.015.059-1.506 5.867-2.932 8.813-1.162 2.402-3 2.436-3.099 2.436h-12.826v-13c3 0 5.728-4 5.728-7.275 0-3.725 1.433-3.725 2.142-3.725 1.327 0 1.978 1.345 1.978 4 0 2.872-.832 4.525-.839 4.537-.161.31-.155.682.027.981.181.299.5.482.849.482h6.942c.922 0 1.551.215 1.866.64.467.626.286 1.705.164 2.112m-23.857 10.248v-10c0-1.795.659-1.981.855-2h2.145v13h-2.173c-.829 0-.827-.648-.827-1m25.309-13.54c-.713-.969-1.886-1.46-3.482-1.46h-5.519c.26-.932.519-2.285.519-4 0-5.221-2.507-6-4-6-1.909 0-4.185.993-4.185 5.725 0 2.206-1.923 5.275-3.815 5.275h-4-.011c-1.034.011-2.816.862-2.816 4v10.02c0 1.198.675 2.979 2.827 2.979h16.971.035c.364 0 3.224-.113 4.894-3.564 1.514-3.127 3.01-8.942 3.056-9.14.071-.23.664-2.289-.474-3.836"
                  ></path>
                </svg>
              </i>
            </div>
          </div>
          <div class="bottom">
            <p>{{ item.content }}</p>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { songtalk } from "@/api/play";
import ItemTitle from "@/components/recommend/ItemTitle.vue";
export default {
  components: {
    ItemTitle,
  },
  data() {
    return {
      MusicID: this.$store.state.MusicID,
      commentList: [],
    };
  },
  created: function () {
    if (this.$route.path == "/play") {
      songtalk(this.MusicID).then((res) => {
        this.commentList = res.data.hotComments;
      });
    } 
  },
  filters: {
    formatdate(item) {
      let d = new Date(Number(item));
      let year = d.getFullYear().toString();
      let mo = (d.getMonth() + 1).toString().padStart(2, "0");
      let da = d.getDate().toString();
      let time = year + "年" + mo + "月" + da + "日";
      return time;
    },
  },
};
</script>

<style lang="scss" scoped>
.comments {
  margin: 0 vw(20);
  ul {
    li {
      display: flex;
      padding-top: vw(20);
      align-content: center;
      width: 100%;
      .imgbox {
        border-radius: 50%;
        overflow: hidden;
        width: 30px;
        height: 30px;
        background-color: #fff;
        margin-right: vw(10);
        flex: 1 0 30px;
        img {
          width: 100%;
        }
      }
      .cmtbox {
        width: 100%;
        border-bottom: solid 1px #7d7d7d;
        .head {
          display: flex;
          justify-content: space-between;
          align-content: center;
          .textbox {
            flex-grow: 1;
            p {
              font-size: vw(25);
              color: hsla(0, 0%, 100%, 0.7);
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 1;
              -webkit-box-orient: vertical;
            }
            span {
              font-size: vw(14);
              color: hsla(0, 0%, 100%, 0.3);
            }
          }
          .count {
            display: flex;
            align-content: center;
            p {
              font-size: vw(25);
              color: #999;
            }
            i {
              display: inline-block;
              width: 14px;
              height: 14px;
              margin-left: 6px;
              line-height: 0;
              vertical-align: middle;
              cursor: pointer;
              .u-svg {
                vertical-align: middle;
                background-position: 0 0;
                background-size: contain;
                background-repeat: no-repeat;
              }
            }
          }
        }
        .bottom {
          margin: vw(10) 0;
          p {
            font-size: vw(28);
            color: #fff;
          }
        }
      }
    }
  }
}
</style>>

